import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'dva'
import { Row, Col, Card ,DatePicker,Table,Tag} from 'antd'
import { color } from 'utils'
import List from './List'
import Searchs from './searchBottom'
import Details from './details'
import Modal from './modal'

const Search = ({ location, dispatch, search, loading }) => {
	const {showDetails,visible,depTypes,userList,list,details,pagination1,params,department2,depUser,infoData} = search
	const listProps ={
		name:1,
		list1:[],
		depTypes,
		userList,
		onSearch(params){
			dispatch({
				type:'search/searchList',
				payload:{
					...params
				}
			})
		},
		showDetail(id){
	    	  	dispatch({
	        		type: 'search/showDet',
	        		payload:{number:id}
	   		})
	    },
	    showList(){
	    		dispatch({
	        		type: 'search/showLis',
	        		payload:{}
	   		})
	    },
//	    onEidt(id){
//			dispatch({
//	        		type: 'search/info',
//	        		payload: {number:id}
//	   		})
//		},
		onDeleteItem(item){
			dispatch({
				type: 'search/delete',
        			payload: item
			})
		},
		onComponent(item){
			dispatch({
				type: 'search/complete',
        			payload: item
			})
		}
	}
	const ListPops={
		list,
		pagination1,
		showDetails,
		params,
		showDetail(id){
	    	  	dispatch({
	        		type: 'search/showDet',
	        		payload:{number:id}
	   		})
	    },
	    onDeleteItem(item){
			dispatch({
				type: 'search/delete',
        			payload: item
			})
		},
		onComponent(item1,item2){
			dispatch({
				type: 'search/complete',
        			payload: {
        				number:item1,
        				state:item2,
        			}
			})
		},
		onEidt(item,item1){
			dispatch({
	        		type: 'search/info',
	        		payload: {
		          id: item
		        }
	   		}),
	   		dispatch({
	        		type: 'search/dep',
	        		payload: {
		          parentId: item1
		        }
	   		})
		},
		onPageChange (page) {
          const { query, pathname } = location
          dispatch({
                type: 'search/searchList',
                payload: {
                  ...query,
                  createUserId:params.users,
			      type:params.type,
				  state:params.state,
				  title:params.title,
				  number:params.number,
				  startTime:params.strTime,
				  endTime:params.endTime,
                  page: page.current,
                	  pageSize: page.pageSize
                }
              })
	       }, 
	}
	const infoProps ={
		visible,
		department2,
		depUser,
		infoData,
//		onEidt(item){
//			dispatch({
//	        		type: 'search/info',
//	        		payload: {
//		          currentItem: item
//		        }
//	   		})
//		},
		onOk(params){
			dispatch({
	        		type: 'search/update',
	        		payload:{
	        			...params
	        		}
	   		})
		},
		onCancels(){
			dispatch({
	        		type: 'search/onCancel',
	        		payload:{}
	   		})
		},
		onUsers(value){
			dispatch({
	        		type: 'search/users',
	        		payload:{organizationId:value}
	   		})
		}
	}
	const detailsProps ={
		details,
	    showList(){
	    		dispatch({
	        		type: 'search/showLis',
	        		payload:{}
	   		})
	    },		
	}
	
    return (
      <div className="content-inner" style={{backgroundColor:'transparent',padding:0}}>
      	<div style={{display:showDetails?"none":"block"}}>
	      	<Searchs {...listProps}/>
	      	<List {...ListPops}/>
	      	<Modal {...infoProps}/>
	    </div>
	    <div style={{display:showDetails?"block":"none"}}>
	    		<Details {...detailsProps}/>
	    </div>
      </div>
    )
  
}
export default connect(({ search, loading }) => ({ search, loading }))(Search)
